package com.googlecode.chigs.web;

import java.util.Properties;

import com.googlecode.chigs.web.util.PropertyUtils;
import com.googlecode.chigs.web.util.PropertyUtils.MergeMode;

/**
 * Application-wide configuration settings for Brix Demo Application
 * 
 * @author igor.vaynberg
 * 
 */
public class ApplicationProperties {

	private final Properties properties;

	public ApplicationProperties() {
		// load base properties
		String baseProperties = "com/googlecode/chigs/web/application.properties";
		Properties base = PropertyUtils.loadFromClassPath(baseProperties, false);

		// load user-specific property overrides
		String username = System.getProperty("user.name");
		String userProperties = "com/googlecode/chigs/web/application." + username + ".properties";
		Properties user = PropertyUtils.loadFromClassPath(userProperties, false);

		// load system properties
		Properties system = System.getProperties();

		// merge properties
		properties = PropertyUtils.merge(MergeMode.OVERRIDE_ONLY, base, user, system);
	}

	/**
	 * @return jcr default workspace
	 */
	public String getJcrDefaultWorkspace() {
		return properties.getProperty("chigs.jcr.defaultWorkspace");
	}

	/**
	 * @return http port the server is using
	 */
	public int getHttpPort() {
		return Integer.parseInt(properties.getProperty("chigs.httpPort"));
	}

	/**
	 * @return https port the server is using
	 */
	public int getHttpsPort() {
		return Integer.parseInt(properties.getProperty("chigs.httpsPort"));
	}

	public String getWorkspaceDefaultState() {
		return properties.getProperty("chigs.jcr.defaultWorkspaceState");
	}
}
